package exer;

/**
 * @author shkstart
 * @create 2022-08-14-22:12
 */
public class jian2_27 {
    public boolean isPalindrome(ListNode head) {

            ListNode oldHead = head;
            ListNode fast = head;
            ListNode low = head;
            while(fast.next!=null||fast.next.next!=null){
                low = low.next;
                fast = fast.next.next;
            }
        ListNode newHead = low.next;
            low.next=null;

//            此时low是中间节点


            ListNode perv = newHead;
            ListNode cur = newHead.next;
            while(cur!=null) {
                ListNode next = cur.next;
                cur.next = perv;
                perv.next = null;
                perv = cur;
                cur = next;
//            此时perv是反转后的头节点
            }

            while(true){
                if (oldHead.val == perv.val) {
                    oldHead=oldHead.next;
                    perv = perv.next;
                }else{
                    return false;

                }
            }
    }

}
